package T467;

public class Main {
}

class Solution {

    public int findSubstringInWraproundString2(String s) {
        char[] cArr = s.toCharArray();
        int n = cArr.length;
        int[] dp = new int[26];
        dp[cArr[0]-'a'] = 1;
        int len = 1;
        for(int i = 1; i<n; i++) {
            //是否相邻
            if((cArr[i]=='a'&&cArr[i-1]=='z')||(cArr[i-1]+1==cArr[i])) {
                len++;
            }else {
                len = 1;
            }
            dp[cArr[i]-'a'] = Math.max(dp[cArr[i]-'a'], len);
        }
        int sum = 0;
        for(int i = 0; i<26 ;i++) {
            sum += dp[i];
        }
        return sum;
    }
    public static int findSubstringInWraproundString1(String s) {
        int n = s.length();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.charAt(i) - 'a';
        }
        int[] dp = new int[26];
        int len = 1;
        dp[arr[0]] = 1;
        for (int i = 1; i < n; i++) {
            int cur = arr[i];
            int pre = arr[i - 1];
            if ((cur == 0 && pre == 25) || (cur - 1 == pre)) {
                len++;
            }else {
                len = 1;
            }
            dp[cur] = Math.max(len, dp[cur]);
        }
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            ans += dp[i];
        }
        return ans;
    }
}